package aperturescience.test;

import org.json.JSONException;
import org.restlet.resource.ClientResource;

import aperturescience.types.Action;
import junit.framework.TestCase;

public class CreateStateMachinery extends TestCase {
	String[] definedStates = {
		"Hyperdynamic,Acute Distress,Acute Tubular Necrosis",	//0
		"Normal,Acute Distress,Acute Tubular Necrosis",			//1
		"Hypotensive,Acute Distress,Acute Tubular Necrosis",	//2
		"Hyperdynamic,Normal,Acute Tubular Necrosis",			//3
		"Normal,Normal,Acute Tubular Necrosis",					//4
		"Hypotensive,Normal,Acute Tubular Necrosis",			//5
		"Hyperdynamic,Somnolent,Acute Tubular Necrosis",		//6
		"Normal,Somnolent,Acute Tubular Necrosis",				//7
		"Hypotensive,Somnolent,Acute Tubular Necrosis",			//8

		"Hyperdynamic,Acute Distress,Normal",					//9
		"Normal,Acute Distress,Normal",							//10
		"Hypotensive,Acute Distress,Normal",					//11
		"Hyperdynamic,Normal,Normal",							//12
		"Normal,Normal,Normal",									//13
		"Hypotensive,Normal,Normal",							//14
		"Hyperdynamic,Somnolent,Normal",						//15
		"Normal,Somnolent,Normal",								//16
		"Hypotensive,Somnolent,Normal",							//17

		"Hyperdynamic,Acute Distress,Pre-renal",				//18
		"Normal,Acute Distress,Pre-renal",						//19
		"Hypotensive,Acute Distress,Pre-renal",					//20
		"Hyperdynamic,Normal,Pre-renal",						//21
		"Normal,Normal,Pre-renal",								//22
		"Hypotensive,Normal,Pre-renal",							//23
		"Hyperdynamic,Somnolent,Pre-renal",						//24
		"Normal,Somnolent,Pre-renal",							//25
		"Hypotensive,Somnolent,Pre-renal"};						//26

	Action painMed, fluid, oxygen, metoprolol, narcan;
	ClientResource actionResource;
	String actionURL = "http://plato.cs.virginia.edu:8080/ApertureScience/actions/";
	Action[] actions = new Action[5];
	
	protected void setUp() throws Exception {
		super.setUp();
		actionResource = new ClientResource(actionURL);
		try {
			painMed = new Action("Pain Medication","Pain Medication Description");
			painMed.addTransition(definedStates[2],definedStates[0]);
			painMed.addTransition(definedStates[5],definedStates[4]);
			painMed.addTransition(definedStates[7],definedStates[5]);
			painMed.addTransition(definedStates[8],definedStates[7]);
			painMed.addTransition(definedStates[14],definedStates[13]);
			painMed.addTransition(definedStates[17],definedStates[13]);
			painMed.addTransition(definedStates[20],definedStates[19]);
			painMed.addTransition(definedStates[23],definedStates[22]);
			actions[0] = painMed;

			fluid = new Action("Fluid Bolus","Fluid Bolus Description");
			fluid.addTransition(definedStates[0],definedStates[1]);
			fluid.addTransition(definedStates[2],definedStates[1]);
			fluid.addTransition(definedStates[3],definedStates[13]);
			fluid.addTransition(definedStates[4],definedStates[14]);
			fluid.addTransition(definedStates[5],definedStates[14]);
			fluid.addTransition(definedStates[6],definedStates[7]);
			fluid.addTransition(definedStates[7],definedStates[5]);
			fluid.addTransition(definedStates[9],definedStates[10]);
			fluid.addTransition(definedStates[12],definedStates[13]);
			fluid.addTransition(definedStates[15],definedStates[16]);
			fluid.addTransition(definedStates[17],definedStates[14]);
			fluid.addTransition(definedStates[18],definedStates[19]);
			fluid.addTransition(definedStates[19],definedStates[10]);
			fluid.addTransition(definedStates[21],definedStates[22]);
			fluid.addTransition(definedStates[24],definedStates[25]);
			actions[1] = fluid;
		
			oxygen = new Action("Oxygen","Oxygen Description");
			oxygen.addTransition(definedStates[0],definedStates[3]);
			oxygen.addTransition(definedStates[2],definedStates[3]);
			oxygen.addTransition(definedStates[6],definedStates[3]);
			oxygen.addTransition(definedStates[7],definedStates[4]);
			oxygen.addTransition(definedStates[8],definedStates[5]);
			oxygen.addTransition(definedStates[10],definedStates[13]);
			oxygen.addTransition(definedStates[15],definedStates[12]);
			oxygen.addTransition(definedStates[16],definedStates[13]);
			oxygen.addTransition(definedStates[17],definedStates[14]);
			oxygen.addTransition(definedStates[24],definedStates[21]);
			oxygen.addTransition(definedStates[25],definedStates[22]);
			oxygen.addTransition(definedStates[26],definedStates[23]);
			actions[2] = oxygen;
		
			metoprolol = new Action("Metoprolol","Metolprolol Description");
			metoprolol.addTransition(definedStates[0],definedStates[1]);
			metoprolol.addTransition(definedStates[1],definedStates[0]);
			metoprolol.addTransition(definedStates[2],definedStates[1]);
			metoprolol.addTransition(definedStates[5],definedStates[4]);
			metoprolol.addTransition(definedStates[8],definedStates[7]);
			metoprolol.addTransition(definedStates[11],definedStates[10]);
			metoprolol.addTransition(definedStates[14],definedStates[13]);
			metoprolol.addTransition(definedStates[17],definedStates[13]);
			metoprolol.addTransition(definedStates[20],definedStates[19]);
			metoprolol.addTransition(definedStates[23],definedStates[22]);
			metoprolol.addTransition(definedStates[24],definedStates[25]);
			metoprolol.addTransition(definedStates[26],definedStates[25]);
			actions[3] = metoprolol;

			narcan = new Action("Narcan","Narcan Description");
			narcan.addTransition(definedStates[0],definedStates[3]);
			narcan.addTransition(definedStates[2],definedStates[3]);
			narcan.addTransition(definedStates[8],definedStates[9]);
			narcan.addTransition(definedStates[9],definedStates[12]);
			narcan.addTransition(definedStates[10],definedStates[13]);
			narcan.addTransition(definedStates[11],definedStates[14]);
			narcan.addTransition(definedStates[17],definedStates[14]);
			narcan.addTransition(definedStates[18],definedStates[21]);
			narcan.addTransition(definedStates[19],definedStates[22]);
			narcan.addTransition(definedStates[20],definedStates[23]);
			narcan.addTransition(definedStates[24],definedStates[25]);
			narcan.addTransition(definedStates[25],definedStates[22]);
			narcan.addTransition(definedStates[26],definedStates[23]);
			actions[4] = narcan;
			
		} catch(JSONException e) {System.out.println(e);}
	}
	
	public void testAddTransitionTo() {
		for (int i=0; i<5; i++) {
			actionResource.setReference(actionURL+(i+1));
			actionResource.put(actions[i]);
		}
	}

}
